package com.mgetwd.springbootweb.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {
    private static final String OK = "0";

    private static final String FAIL = "1";

    private String status;

    private String msg;

    private T data;

    public static <T> Result<T> OK(String msg) {
        return OK("", null);
    }

    public static <T> Result<T> OK(T data) {
        return OK("", data);
    }

    public static <T> Result<T> OK(String msg, T data) {
        return build(OK, msg, data);
    }

    public static <T> Result<T> FAIL(String msg,T data){
        return build(FAIL,msg,data);
    }

    public static <T> Result<T> FAIL(String msg){
        return build(FAIL,msg,null);
    }
    public static <T> Result<T> build(String status, String msg, T data) {
        Result<T> result = new Result<>();
        result.setStatus(status);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
}
